//logs.js
const util = require('../../utils/util.js')

Page({
 
  cls2: function (options) {
    console.log(options)
    var producturl = options.currentTarget.dataset.prourl ; 
    wx.setStorageSync("producturl", producturl)
    wx.navigateTo({
      url: '/pages/dd1/dd1' 
    })
  },
 


  data: {
    data: 0,
    arrays:'',
    showView: false,
    isChecked: false,
    isChecked2: false,
    isChecked1: false,
  },

  click: function () {
    var key;
    var id = wx.getStorageSync('key');
    wx.removeStorage({
      key: 'key'
    })
    if (id == 5) {
      key = 4;
    } else {
      key = 5;
    }
    console.log(key)
    var array;
    var that = this;
    wx.request({
      url: 'https://www.songxiaohui.club/easyprice/shop/order?type=' + key, //仅为示例，非真实的接口地址
      success: function (res) {
        if (res.data.data != null) {
          wx.setStorageSync('array', res.data.data);
          wx.setStorageSync('key', key);
          wx.navigateTo({
            url: '../detail/detail',
            success: function (res) {             
              console.log(res)
            },
            fail: function (err) {
              console.log(err)
            }

          })
        }

      },
      fail: function (err) {
        console.log(err)
      }
    }),
      that.setData({
        arrays: array,
      })
  },
  
  select: function (options) {
    var that = this;
    that.setData({
      isChecked: true
    })
    var status = options.currentTarget.id;    
    wx.setStorageSync('status', status);
  },

  select1: function (options) {
    var that = this;
    that.setData({
      isChecked1: true
    })
    var status = options.currentTarget.id;
    wx.setStorageSync('status', status);
  },

  select2: function (options) {
    var that = this;
    that.setData({
      isChecked2: true
    })
    var status = options.currentTarget.id;
  
    wx.setStorageSync('status', status);
  },

  cancel:function(){
    wx.removeStorageSync('status');
  },

  sure: function () {
    var status = wx.getStorageSync('status');
    console.log(status)
    wx.removeStorageSync('status');
    var array;
    var that = this;
    wx.request({
      url: 'https://www.songxiaohui.club/easyprice/shop/order?type=' + status, //仅为示例，非真实的接口地址

      success: function (res) { 
        if (res.data.data != null) {     
          wx.setStorageSync('array', res.data.data);
          wx.setStorageSync('key', 4); 
          wx.navigateTo({
            
            url: '../detail/detail',
            success: function (res) {
              console.log(res)
            },
            fail: function (err) {
              console.log(err)
            }
          })
        }

      },
      fail: function (err) {
        console.log(err)
      }
    }),
      that.setData({
        arrays: array,
      })


  },

  onLoad: function (option) {
    var that = this;

    var array = wx.getStorageSync('array');
    console.log(array)
    wx.removeStorageSync('array')
    that.setData({
      arrays: array,
    })
  },

  oselect:function(){
    var that = this;
    that.setData({
      showView: (!that.data.showView),
      isChecked: false

    })
  }
})
